<template>
  <div>
    <a-dropdown v-if="currentUser && currentUser.name" placement="bottomRight">
    <span class="ant-pro-account-avatar">
      <a-avatar
        size="small"
        src="https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png"
        class="antd-pro-global-header-index-avatar"
      />
      <span>{{ currentUser.name }}</span>
    </span>
      <template v-slot:overlay>
        <a-menu class="ant-pro-drop-down menu" :selected-keys="[]">
<!--          <a-menu-item v-if="menu" key="center" @click="visible = true">-->
<!--            <a-icon type="user" />-->
<!--            {{ $t('menu.account.center') }}-->
<!--          </a-menu-item>-->
          <!-- <a-menu-item v-if="menu" key="settings" @click="handleToSettings">
            <a-icon type="setting" />
            {{ $t('menu.account.settings') }}
          </a-menu-item> -->
          <a-menu-divider v-if="menu" />
          <a-menu-item key="logout" @click="handleLogout">
            <a-icon type="logout" />
            {{ $t('menu.account.logout') }}
          </a-menu-item>
        </a-menu>
      </template>
    </a-dropdown>
    <span v-else>
    <a-spin size="small" :style="{ marginLeft: 8, marginRight: 8 }" />
  </span>
<!--    <div v-if="visible">-->
<!--      <UserInfoModal @cancel="cancel"/>-->
<!--    </div>-->
  </div>
</template>

<script>
import { Modal } from 'ant-design-vue'
import { Ellipsis } from '@/components'
import STable from '@/components/Table'
// import UserInfoModal from '@/views/account/userInfo'

export default {
  name: 'AvatarDropdown',
  components: { Ellipsis, STable },
  props: {
    currentUser: {
      type: Object,
      default: () => null,
    },
    menu: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      visible: false,
    }
  },
  methods: {
    cancel() {
      this.visible = false;
    },
    handleToSettings() {
      this.$router.push({ path: '/userInfo' })
    },
    handleLogout(e) {
      Modal.confirm({
        title: '温馨提示',
        content: '您确定要退出登录吗？',
        onOk: () => {
          return this.$store.dispatch('Logout').then(() => {
            this.$router.push({ name: 'login' })
          })
        },
        onCancel() {},
      })
    },
  },
}
</script>

<style lang="less" scoped>
.ant-pro-drop-down {
  :deep(.action) {
    margin-right: 8px;
  }
  :deep(.ant-dropdown-menu-item) {
    min-width: 160px;
  }
}
</style>
